package com.sh.two.poxy;

import com.sh.two.annotation.ShFeignClient;
import lombok.SneakyThrows;

import java.lang.reflect.Proxy;

/**
 * 代理对象工厂
 */
public class ShClientFactory {
 
    @SneakyThrows
    public Object getInstance(String className) {
        Class<?> aClass = Class.forName(className);
        ShFeignClient annotation = aClass.getAnnotation(ShFeignClient.class);
        return Proxy.newProxyInstance(
                aClass.getClassLoader(),
                new Class[]{aClass},
                new ShClientProxy(annotation.baseUrl(), annotation.prefix()));
    }
}